//日期相关的工具代码
let dateUtil = {
	// str转date
	str2date: function(dateString) {
		dateString.replace(/-/g, "/");
		return new Date(dateString);
	},
	// date转str
	date2Str: function(date) {
		let year = date.getFullYear(); //年
		let month = date.getMonth() + 1; //月
		let day = date.getDate(); //日
		let hours = date.getHours(); //时
		let min = date.getMinutes(); //分
		let second = date.getSeconds(); //秒
		return year + "-" +
			(month > 9 ? month : "0" + month) + "-" +
			(day > 9 ? day : ("0" + day)) + " " +
			(hours > 9 ? hours : ("0" + hours)) + ":" +
			(min > 9 ? min : ("0" + min)) + ":" +
			(second > 9 ? second : ("0" + second));
	},
	// 把date转成想要的格式
	date2Str_Format1: function(date) {
		let year = date.getFullYear(); //年
		let month = date.getMonth() + 1; //月
		let day = date.getDate(); //日
		return `${year}年${month}月${day}日`
	},
	date2Str_Format2: function(date) {
		let hours = date.getHours(); //时
		let min = date.getMinutes(); //分
		return `${hours > 9 ? hours : ("0"+hours)}:${min > 9 ? min : ("0"+min)}`;
	},
	date2Str_Format3: function(date) {
		let month = date.getMonth() + 1; //月
		let day = date.getDate(); //日
		return `${(month) > 9 ? (month):"0"+(month)}-${day > 9 ? day : ("0"+day)}`;
	},
	// 当天的0点
	minTimeRange: function() {
		return new Date(new Date().setHours(0, 0, 0, 0));
	},
	// 当天的23：59
	maxTimeRange: function() {
		return new Date(new Date().setHours(0, 0, 0, 0) + 24 * 60 * 60 * 1000 - 1);
	},
	// 本周一的date
	getMonday: function() {
		let nowTemp = new Date(); //当前时间
		let oneDayLong = 24 * 60 * 60 * 1000; //一天的毫秒数
		let c_time = nowTemp.getTime(); //当前时间的毫秒时间
		let c_day = nowTemp.getDay() || 7; //当前时间的星期几
		let m_time = c_time - (c_day - 1) * oneDayLong; //当前周一的毫秒时间
		return new Date(m_time); //设置周一时间对象
	}
}
export { dateUtil }
